﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Documents;
using UIWindows.Models;
using UIWindows.Tools.Helper;
using UIWindows.UserControls;

namespace UIWindows.GlobalStatics
{
    [Attributes.Singleton]
    public class LogStatic
    {
        public List<Log4NetModel> LNModels { get; set; }
        public AsyncObservableCollection<RunMessageModel> LogList { get; set; }
        public AsyncObservableCollection<MesLogModel> MesLog { get; set; }
        public AsyncObservableCollection<RunMessageModel> OperationLog { get; set; }
        public LogStatic()
        {
            LogList = new AsyncObservableCollection<RunMessageModel>();
            MesLog = new AsyncObservableCollection<MesLogModel>();
            OperationLog = new AsyncObservableCollection<RunMessageModel>();
            if (!File.Exists(GlobalStatic.Log4NetPath))
            {
                //新建log4net文件
                LNModels = new List<Log4NetModel>() { 
                   new Log4NetModel(){ 
                       LoggerName = "message",
                       DatePattern = "yyyy-MM-dd-HH\".txt\"",
                       SavePath = ".\\logs\\RunLog\\",
                       ConversionPattern = "%date{HH:mm:ss fff}$%-5level$%message$%newline",
                   },
                   new Log4NetModel(){
                       LoggerName = "operation",
                       DatePattern = "yyyy-MM-dd\".txt\"",
                       SavePath = ".\\logs\\OperationLog\\",
                       ConversionPattern = "%date{HH:mm:ss fff}$%-5level$%message$%newline",
                   },
                   new Log4NetModel(){
                       LoggerName = "plc_alarm",
                       DatePattern = "yyyy-MM-dd\".txt\"",
                       SavePath = ".\\logs\\PLCAlarm\\",
                       ConversionPattern = "%date{HH:mm:ss fff}$%-5level$%message$%newline",
                   },
                   #region MES接口日志
                   new Log4NetModel()
                   {
                       LoggerName = "loginCheck",
                       DatePattern = "yyyy-MM-dd\".csv\"",
                       SavePath = ".\\MESlog\\操作员登录校验接口\\",
                       ConversionPattern = "%message %newline",
                   },
                   new Log4NetModel()
                   { 
                       LoggerName = "wIPInStationCheck",
                       DatePattern = "yyyy-MM-dd\".csv\"",
                       SavePath = ".\\MESlog\\在制品进站校验\\",
                       ConversionPattern = "%message %newline",
                   },
                   new Log4NetModel()
                   {
                       LoggerName = "rawMaterialFeedingCheck",
                       DatePattern = "yyyy-MM-dd\".csv\"",
                       SavePath = ".\\MESlog\\原材料投料校验\\",
                       ConversionPattern = "%message %newline",
                   },
                   new Log4NetModel()
                   {
                       LoggerName = "stateAndStopReasonUpload",
                       DatePattern = "yyyy-MM-dd\".csv\"",
                       SavePath = ".\\MESlog\\设备状态_停机原因上传接口\\",
                       ConversionPattern = "%message %newline",
                   },
                   new Log4NetModel()
                   {
                       LoggerName = "heartBeat",
                       DatePattern = "yyyy-MM-dd\".csv\"",
                       SavePath = ".\\MESlog\\设备在线检测\\",
                       ConversionPattern = "%message %newline",
                   },
                   new Log4NetModel()
                   {
                       LoggerName = "processDataUpload",
                       DatePattern = "yyyy-MM-dd\".csv\"",
                       SavePath = ".\\MESlog\\设备过程参数上传\\",
                       ConversionPattern = "%message %newline",
                   },
                   new Log4NetModel()
                   {
                       LoggerName = "alarmUpload",
                       DatePattern = "yyyy-MM-dd\".csv\"",
                       SavePath = ".\\MESlog\\设备报警上传\\",
                       ConversionPattern = "%message %newline",
                   },
                   new Log4NetModel()
                   {
                       LoggerName = "manualSupplyLiquidUpload",
                       DatePattern = "yyyy-MM-dd\".csv\"",
                       SavePath = ".\\MESlog\\人工补液上传接口\\",
                       ConversionPattern = "%message %newline",
                   },
                   new Log4NetModel()
                   {
                       LoggerName = "getRecipeDetail",
                       DatePattern = "yyyy-MM-dd\".csv\"",
                       SavePath = ".\\MESlog\\开机参数明细请求接口\\",
                       ConversionPattern = "%message %newline",
                   },
                   new Log4NetModel()
                   {
                       LoggerName = "resultDataUploadAssembly",
                       DatePattern = "yyyy-MM-dd\".csv\"",
                       SavePath = ".\\MESlog\\产品结果数据上传\\",
                       ConversionPattern = "%message %newline",
                   },
                   new Log4NetModel()
                   {
                       LoggerName = "resultDataUploadFitstCheck",
                       DatePattern = "yyyy-MM-dd\".csv\"",
                       SavePath = ".\\MESlog\\首件检验上传\\",
                       ConversionPattern = "%message %newline",
                   },
                   new Log4NetModel()
                   {
                       LoggerName = "oneClickSpotCheck",
                       DatePattern = "yyyy-MM-dd\".csv\"",
                       SavePath = ".\\MESlog\\一键点检\\",
                       ConversionPattern = "%message %newline",
                   },
                   new Log4NetModel()
                   {
                       LoggerName = "getIDCardCheck",
                       DatePattern = "yyyy-MM-dd\".csv\"",
                       SavePath = ".\\MESlog\\员工卡号校验\\",
                       ConversionPattern = "%message %newline",
                   },
                   new Log4NetModel()
                   {
                       LoggerName = "getFingerCheck",
                       DatePattern = "yyyy-MM-dd\".csv\"",
                       SavePath = ".\\MESlog\\指纹等级校验\\",
                       ConversionPattern = "%message %newline",
                   },
                   new Log4NetModel()
                   {
                       LoggerName = "upEquipRealTimeData",
                       DatePattern = "yyyy-MM-dd\".csv\"",
                       SavePath = ".\\MESlog\\实时数据上传\\",
                       ConversionPattern = "%message %newline",
                   },
                   new Log4NetModel()
                   {
                       LoggerName = "upRealtimeStatus",
                       DatePattern = "yyyy-MM-dd\".csv\"",
                       SavePath = ".\\MESlog\\设备实时状态\\",
                       ConversionPattern = "%message %newline",
                   },
                   new Log4NetModel()
                   {
                       LoggerName = "wastageDataUpload",
                       DatePattern = "yyyy-MM-dd\".csv\"",
                       SavePath = ".\\MESlog\\设备能耗结果数据上传\\",
                       ConversionPattern = "%message %newline",
                   },
                   #endregion
                };
                File.WriteAllText(".\\log4net.config", Log4NetHelper.WriteLog4NetXml(LNModels));
            }
            else
            {
                LNModels = Log4NetHelper.ReadLog4NetConfig(GlobalStatic.Log4NetPath);
            }
            _ = log4net.Config.XmlConfigurator.Configure(new FileInfo(GlobalStatic.Log4NetPath));
        }
    }
}
